package org.fioma.tree.bytes;

import org.fioma.general.Tools;
import org.fioma.tree.LabelRef;

public class LabelRefBytesIndex extends LabelRef<LabelRefBytesIndex, BytesIndexed> {

//	private LabelRefBytesIndex(byte[] word, int index, int start, int length, LabelRefBytesIndexFactory labelFactory) {
//		this(new BytesIndexed(word, index), start, length, labelFactory);
//	}
//
	public LabelRefBytesIndex(BytesIndexed word, int start, int length, LabelRefBytesIndexFactory labelFactory) {
		super(word, start, length, labelFactory);
	}

//	private LabelRefBytesIndex(BytesIndexed word, LabelRefBytesIndexFactory labelFactory) {
//		this(word, 0, word.getWord()[0], labelFactory);
//	}
//
	public int getIndex() {
		return getWord().getIndex();
	}

	@Override
	public byte getByte(int pos) {
		if (pos < 0 || pos >= getLength()) {
			throw new RuntimeException("Position " + pos + " invalid in the word with length " + getLength());
		}
		return Tools.getByte(getWord().getWord(), getStart() + pos);
	}

	public int getMinsmatch(LabelRefBytesIndex word) {
		return Tools.getMismatch(getWord().getWord(), getStart(), getLength(), word.getWord().getWord(), word.getStart(), word.getLength());
	}

	@Override
	public int getWordLength() {
		return getWord().getLength();
	}

	@Override
	public byte[] getBytes() {
		return getWord().getWord();
	}
}
